fun main() {
    //if
    val d: Int
    val check = true
    if (check) {
        d = 1
    } else {
        d = 2
    }
    println(d)
    //三元表达式
    //kotlin没有三元运算符
    //用if替代
    val a = 1
    val b = 2
    println(if (a > b) a else b)
    //When
    //分支语句
    val obj = "Hello"
    when (obj) {
        "1" -> println("one")
        "Hello" -> println("greeting")
        else -> println("unknown")
    }
    //分配给变量
    val result = when (obj) {
        // If obj equals "1", sets result to "one"
        "1" -> "One"
        // If obj equals "Hello", sets result to "Greeting"
        "Hello" -> "Greeting"
        // Sets result to "Unknown" if no previous condition is satisfied
        else -> "Unknown"
    }
    println(result)
    //匹配变量
    val temp = 18
    val description = when {
        // If temp < 0 is true, sets description to "very cold"
        temp < 0 -> "very cold"
        // If temp < 10 is true, sets description to "a bit cold"
        temp < 10 -> "a bit cold"
        // If temp < 20 is true, sets description to "warm"
        temp < 20 -> "warm"
        // Sets description to "hot" if no previous condition is satisfied
        else -> "hot"
    }
    println(description)

}